{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from efficient_kan import KANLinear\n",
    "from fastkan import FastKANLayer\n",
    "\n",
    "eklayer = KANLinear(100, 100).cuda()\n",
    "fklayer = FastKANLayer(100, 100).cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.randn(8, 100).cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "742 µs ± 186 µs per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n",
      "223 µs ± 19 µs per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit -r10 -n1000 y = eklayer(x)\n",
    "%timeit -r10 -n1000 y = fklayer(x, time_benchmark=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.16 ms ± 18.8 µs per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n",
      "925 µs ± 13.6 µs per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit -r10 -n1000 eklayer(x).sum().backward()\n",
    "%timeit -r10 -n1000 fklayer(x).sum().backward()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
